/***************************************************************************
 *   This file is part of KTagger                                          *
 *   Copyright (C) 2010 by Luca Bellonda                                   *
 *   lbellonda _at_ gmail.com                                              *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef ADDTAGS_H
#define ADDTAGS_H

#include <QMainWindow>
#include <QCompleter>
#include <QTableWidgetItem>
#include <QListWidgetItem>
#include "tagProfile.h"

namespace Ui
{
class AddTags;
}

namespace ktagger
{
class KTaggerApplication;
};

class AddTags : public QMainWindow
{
    Q_OBJECT
public:
    AddTags(ktagger::KTaggerApplication *application, QWidget *parent = 0);
    ~AddTags();


    void go();

    void setTargetResource(const QString &resourcePath);
    void setCurrentProfileTags(QStringList currentProfileTags);


protected:
    void changeEvent(QEvent *e);
    void closeEvent(QCloseEvent * event);
    void resizeEvent(QResizeEvent * event);

private:
    Ui::AddTags *ui;
    ktagger::KTaggerApplication    *_application;
    QCompleter                     *_tagsCompleter;
    QStringList                     _allTags;
    QVector<TagProfile*>            *_profiles;
    bool                            _loadingData;


    QString _resource;
    QStringList _currentProfileTags;
    QStringList _currentlyAssignedTags;

    void refineUI();
    void loadLastUsedTags();
    void loadAllTags();
    void loadProfileTag();
    void loadOtherTags(const QString &tag);
    void loadResourceTags();
    void loadProfiles();
    void showEvent(QShowEvent * event);

    void showOtherTags(const bool isShow);
    void addTagToSet(const QString &text);
    QStringList getConfirmedTags();
    void cleanData();

    bool saveTags(QStringList &confirmedTags, QStringList &currentlyAssignedTags);
    bool saveTagSetConfiguration(const QStringList &confirmedTags);


private slots:
    void on_addTagButton_clicked();
    void on_chooseTag_editTextChanged(const QString & text);
    void on_tableTags_itemClicked(QTableWidgetItem * item);
    void on_listCompanionTags_itemClicked(QListWidgetItem * item);
    void on_addTagsFromCurrentProfile_clicked();
    void on_cmdOK_clicked();
    void on_cmdCancel_clicked();
    void on_recentlyUsed_currentIndexChanged(int index) ;
    void on_profiles_currentIndexChanged(int index);
};

#endif // ADDTAGS_H
